package com.focus.xyz.other.cases;

import com.focus.xyz.core.common.webdriver.DriverFactory;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.os.WindowsUtils;
import org.testng.Assert;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;

import java.util.concurrent.TimeUnit;

/**
 * Created by chenmeng on 2016/5/10.
 */
public class AutoItTest {
    private WebDriver driver;

    @Parameters({"browser","nodeUrl"})
    @BeforeMethod(alwaysRun = true)
    public void setUp(String browser,String nodeUrl) throws Exception{
        driver = DriverFactory.getDriver(nodeUrl).getBrowser(browser);
        driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
        driver.get("F:\\upload.html");
    }

    @AfterMethod(alwaysRun = true)
    public void tearDown(){
        try{
            if(driver!=null){
                driver.close();
                driver.quit();
            }
        }catch (Exception e){
            WindowsUtils.tryToKillByName("iexplore.exe");
        }

    }

    @Test(enabled = false)
    public void testRemoteDriver(){
        driver.findElement(By.name("file")).click();
        try {
            Thread.sleep(2000l);
            Runtime.getRuntime().exec("E:\\cimon\\union\\data\\autoit\\upload_x64.exe");
            Thread.sleep(10000l);
            Assert.assertTrue(driver.getPageSource().contains("upload_file.txt"));
        } catch (Exception e) {
            e.printStackTrace();
        }
        Assert.assertEquals("selenium_百度搜索",driver.getTitle());
    }
}
